<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class model_services extends CI_Model{
    var $table      = "tbl_services";
    var $tbl_city   = "master_city";
    var $tbl_state  = "master_state";
    var $primary    = "id_services";
    
    public function __construct()
    {
        parent::__construct();
    }
    /*
     * author dinov
     * 20141017
     * retrieve all services data
     */
    function get_all(){
        $q = $this->db->query("SELECT A.*,C.city_name,S.state_name FROM `".$this->table."` as A "
                . "INNER JOIN `".$this->tbl_city."` as C ON A.city_id = C.city_id "
                . "INNER JOIN `".$this->tbl_state."` as S ON S.state_id = C.city_state_id");
        return $q->result();
    }
    /*
     * author dinov
     * 20141017
     * retrieve city list based on state id
     */
    function get_city_list($condition){
        if(empty($condition)){return FALSE;}
        $this->db->where($condition);
        return $this->db->get($this->tbl_city);
    }
    function save_data($isi){
        if( empty($isi) ) return false;
        if( $this->db->insert($this->table,$isi) ) return true;
        return false;
    }
    /*
     * author dinov
     * 20141020
     * update data in tbl_services
     */
    function update_data($id,$array){
        if(empty($id) || empty($array)) {return FALSE;}
        $this->db->where($this->primary,$id);	
        if($this->db->update($this->table,$array)) {return TRUE;}
        else return FALSE;
    }
    
    /*
     * author dinov
     * 20141020
     * delete record
     * parameter : ID -> required
     */
    function delete($id){
        if( empty($id) ) {return FALSE;}
        if($this->db->delete($this->table, array($this->primary => $id))) {return TRUE;}
        else {return FALSE;}
    }
    function cek_op(){
        $q = $this->db->query("SELECT * FROM `oportunity`");
        return $q->num_rows();
    }
    function count_by_email($email){
        $q = $this->db->query("SELECT * FROM `$this->table` WHERE `".$this->email."`='$email'");
        return $q->num_rows();
    }
    function select_by_id($id,$mod = "result"){
        $q = $this->db->query("SELECT A.*, B.city_name,B.city_state_id FROM `$this->table` as A "
                . "INNER JOIN `".$this->tbl_city."` as B ON A.city_id=B.city_id WHERE `".$this->primary."`='".$id."'");
        if(strtolower($mod) == "result") return $q->result();
        else return $q->num_rows();
    }
    function login_check($email,$password){
        $q = $this->db->query("SELECT * FROM `$this->table` WHERE `".$this->email."` = '$email' AND `password` = '$password'");
        if($q->num_rows() > 0)return true;
        else return false;
    }
    function login_select($email){
        $q = $this->db->query("SELECT * FROM `$this->table` WHERE `".$this->email."` = '$email'");
        if($q->num_rows() > 0)return $q->row();
        else return false;
    }
    
}
/* End of file model_member.php */
/* Location: ./application/models/model_member.php */
